#ifndef SPARSE_MATRIX_H
#define SPARSE_MATRIX_H

#include "Common.h"

struct Triple {
    int row;
    int col;
    int value;
    Triple(int r = 0, int c = 0, int v = 0) : row(r), col(c), value(v) {}
};

struct CrossNode {
    int row;
    int col;
    int value;
    shared_ptr<CrossNode> right;
    shared_ptr<CrossNode> down;
    CrossNode(int r = 0, int c = 0, int v = 0) 
        : row(r), col(c), value(v), right(nullptr), down(nullptr) {}
};

class SparseMatrixTriplet {
private:
    vector<Triple> data;
    int rows;
    int cols;

public:
    SparseMatrixTriplet(int r, int c);
    
    void addElement(int row, int col, int value);
    
    SparseMatrixTriplet transpose() const;
    
    void print() const;
    
    void interactiveInput();
    
    int getRows() const { return rows; }
    int getCols() const { return cols; }
};

class SparseMatrixCross {
private:
    vector<shared_ptr<CrossNode>> rowHeads;
    vector<shared_ptr<CrossNode>> colHeads;
    int rows;
    int cols;

public:
    SparseMatrixCross(int r, int c);
    
    void addElement(int row, int col, int value);
    
    SparseMatrixCross transpose() const;
    
    void print() const;
    
    void interactiveInput();
    
    static void testSparseMatrix();
    
    static void interactiveTest();
};

#endif